package com.example.onlinemallsystem.config;

import com.example.onlinemallsystem.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class LoginInterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                // 拦截所有需要登录的路径（示例：/user/** 表示所有 /user/ 开头的路径）
                .addPathPatterns("/user/**")
                // 排除不需要拦截的路径（如登录、注册接口）
                .excludePathPatterns("/login", "/register", "/static/**");
    }
}